package com.hxzy.booking.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hxzy.booking.pojo.Booking;
import com.hxzy.booking.pojo.SignIn;
import com.hxzy.booking.service.BookingService;
import com.hxzy.course.pojo.Course;
import com.hxzy.course.pojo.Staff;
import com.hxzy.region.pojo.Region;
import com.hxzy.util.excel.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("booking")
public class BookingController {

    @Autowired
    private BookingService bookingService;

    /**查询所有预约分页
     * @Author hjs
     * @Description //TODO
     * @Date 9:46 2021/9/30
     * @Param [pageNum, pageSize]
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.hxzy.booking.pojo.Booking>
     **/
    @RequestMapping("/findAll.do")
    public Page<Booking> findAll(Integer pageNum, Integer pageSize){
        return bookingService.findAll(pageNum,pageSize);
    }

    /**查询所有未签到的预约分页
     * @Author hjs
     * @Description //TODO
     * @Date 9:46 2021/9/30
     * @Param [pageNum, pageSize]
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.hxzy.booking.pojo.Booking>
     **/
    @RequestMapping("/findAllNotSign.do")
    public Page<Booking> findAllNotSign(Integer pageNum, Integer pageSize){
        return bookingService.findAllNotSign(pageNum,pageSize);
    }

    /**查询所有签到记录分页
     * @Author hjs
     * @Description //TODO
     * @Date 9:47 2021/9/30
     * @Param [pageNum, pageSize]
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.hxzy.booking.pojo.SignIn>
     **/
    @RequestMapping("/findAllSignIn.do")
    public Page<SignIn> findAllSignIn(Integer pageNum, Integer pageSize){
        return bookingService.findAllSignIn(pageNum,pageSize);
    }

    /**查询所有场馆
     * @Author hjs
     * @Description //TODO
     * @Date 9:47 2021/9/30
     * @Param []
     * @return java.util.List<com.hxzy.region.pojo.Region>
     **/
    @RequestMapping("/findAllRegion.do")
    public List<Region> findAllRegion(){
        List<Region> allRegion = bookingService.findAllRegion();
        System.out.println("所有场馆："+allRegion);
        return allRegion;
    }

    /**查询所有教练
     * @Author hjs
     * @Description //TODO
     * @Date 9:47 2021/9/30
     * @Param []
     * @return java.util.List<com.hxzy.course.pojo.Staff>
     **/
    @RequestMapping("/findAllStaff.do")
    public List<Staff> findAllStaff(){
        List<Staff> allStaff = bookingService.findAllStaff();
        System.out.println("所有教练："+allStaff);
        return allStaff;
    }

    /**查询所有课程
     * @Author hjs
     * @Description //TODO
     * @Date 9:47 2021/9/30
     * @Param []
     * @return java.util.List<com.hxzy.course.pojo.Course>
     **/
    @RequestMapping("/findAllCourse.do")
    public List<Course> findAllCourse(){
        List<Course> allCourse = bookingService.findAllCourse();
        System.out.println("所有课程："+allCourse);
        return allCourse;
    }

    /**预约搜索
     * @Author hjs
     * @Description //TODO
     * @Date 9:47 2021/9/30
     * @Param [regionName, coachName, courseName, flag, bookingTime, schoolTime, card, tel, name, pageNum, pageSize]
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.hxzy.booking.pojo.Booking>
     **/
    @RequestMapping("/likeNameCourse.do")
    public Page<Booking> likeNameCourse(String regionName, String coachName, String courseName, Integer flag, String bookingTime, String schoolTime, String card, String tel, String name,Integer pageNum, Integer pageSize){
        Page<Booking> bookings = bookingService.likeNameCourse(regionName,coachName,courseName,flag,bookingTime,schoolTime,card,tel,name,pageNum,pageSize);
        return bookings;

    }

    /**签到搜索
     * @Author hjs
     * @Description //TODO
     * @Date 9:48 2021/9/30
     * @Param [sTime, name, card, pageNum, pageSize]
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.hxzy.booking.pojo.SignIn>
     **/
    @RequestMapping("/searchSign.do")
    public Page<SignIn> searchSign(String sTime, String name, String card,Integer pageNum, Integer pageSize){
        Page<SignIn> signInPage = bookingService.searchSign(sTime, name, card, pageNum, pageSize);
        return signInPage;
    }

    /**查询所有销售
     * @Author hjs
     * @Description //TODO
     * @Date 9:48 2021/9/30
     * @Param []
     * @return java.util.List<com.hxzy.course.pojo.Staff>
     **/
    @RequestMapping("/findAllSell.do")
    public List<Staff> findAllSell(){
        List<Staff> allSell = bookingService.findAllSell();
        System.out.println("所有销售："+allSell);
        return allSell;
    }

    /**添加预约
     * @Author hjs
     * @Description //TODO
     * @Date 9:48 2021/9/30
     * @Param [memberCard, bGender, bTel, stadium, sellName, coachName, bcourseName, bBookingtime, bSchooltime, bFlag, bRemark]
     * @return boolean
     **/
    @RequestMapping("/addBooking.do")
    public boolean addBooking(String memberCard, String bGender, String bTel, String sellName,String bcourseName, Integer bFlag, String bRemark, Integer arrangeId){
        boolean result = bookingService.addBooking(memberCard,bGender,bTel,sellName,bcourseName,bFlag,bRemark,arrangeId);
        System.out.println("添加预约："+result);
        return result;
    }

    /**删除预约
     * @Author hjs
     * @Description //TODO
     * @Date 9:48 2021/9/30
     * @Param [bid]
     * @return boolean
     **/
    @RequestMapping("/deleteBooking.do")
    public boolean deleteBooking(int bid){
        boolean result = bookingService.deleteBooking(bid);
        System.out.println(result);
        return result;
    }

    /**修改预约信息
     * @Author hjs
     * @Description //TODO
     * @Date 9:48 2021/9/30
     * @Param [booking]
     * @return boolean
     **/
    @RequestMapping("/updateBooking.do")
    public boolean updateBooking(Booking booking){
        boolean result = bookingService.updateBooking(booking);
        System.out.println(result);
        return result;
    }

    /**预约签到
     * @Author hjs
     * @Description //TODO
     * @Date 9:49 2021/9/30
     * @Param [bid, coName]
     * @return boolean
     **/
    @RequestMapping("/signInBooking.do")
    public boolean signInBooking(int bid,String coName){
        boolean result = bookingService.signInBooking(bid,coName);
        System.out.println(result);
        return result;
    }

    //导出Excel表
    @RequestMapping("/export")
    public void export(HttpServletResponse response){
        List<Booking> export = bookingService.export();
        ExcelUtils.writeExcel(response,export,Booking.class);
        long t1 = System.currentTimeMillis();
        long t2 = System.currentTimeMillis();
        System.out.println(String.format("write over! cost:%sms", (t2 - t1)));
    }

}
